package cn.zhuizikejithreeig.com.passenger;

import android.Manifest;
import android.app.Dialog;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends BasicActivity implements View.OnClickListener {


    private ImageView mSaoMa;
    String[] permissionss = new String[]{
            Manifest.permission.CAMERA,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.ACCESS_COARSE_LOCATION,
    };


    @Override
    protected boolean actionBarNeedGoon() {
        return true;
    }

    @Override
    public int setContView() {

        return R.layout.activity_main;
    }

    @Override
    protected int setHandIndexShow() {
        return 2;
    }

    @Override
    protected void initView() {
        setTitle("");
        mSaoMa = (ImageView) findViewById(R.id.saoma);

        initLogin();
    }

    private void initLogin() {
        //发起微信登录
        if (CompontApplayCation.iwxapi != null && CompontApplayCation.iwxapi.isWXAppInstalled()) {
            SendAuth.Req req = new SendAuth.Req();
            req.scope = "snsapi_userinfo";
            req.state = "wechat_sdk_demo_test_neng";
            CompontApplayCation.iwxapi.sendReq(req);
        } else {
            Toast.makeText(this, "用户未安装微信", Toast.LENGTH_SHORT).show();
        }
    }

    //监听网络变化
    @Override
    protected void netChengedListen(int netMobile) {
        if (netMobile != -1) {
        }
        System.out.println("网络变化了");
    }

    @Override
    protected void initToDo() {
        mSaoMa.setOnClickListener(this);
        //天机6.0权限管理
        List<String> mPermisionList = new ArrayList<>();
        mPermisionList.clear();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            for (int i = 0; i < permissionss.length; i++) {
                if (ContextCompat.checkSelfPermission(MainActivity.this, permissionss[i]) != PackageManager.PERMISSION_GRANTED) {
                    mPermisionList.add(permissionss[i]);
                }
            }
            if (mPermisionList.size() == 1) {
                getSinglePermission(mPermisionList.get(0));
            } else if (mPermisionList.size() > 1) {
                String[] permissionarrs = new String[mPermisionList.size()];
                for (int i = 0; i < permissionarrs.length; i++) {
                    permissionarrs[i] = mPermisionList.get(i);
                }
                getListPermissions(permissionarrs);
            }
        }

    }


    @Override
    public void onClick(View v) {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            getSinglePermission(Manifest.permission.CAMERA);
            return;
        } else {

            skipOtherActivity(SaoMaActivity.class, false);
//
//            Dialog dialog = DialogUtil.showInfoDialog(MainActivity.this, "提示", "这是提示语");
//            dialog.show();
//            DialogUtil.showInfoDialog1(MainActivity.this, "提示", "这是提示语", "这里确定", "这里取消", new BackCall() {
//                @Override
//                public void deal(int which, Object... obj) {
//                    switch (which) {
//                        case R.id.confirm:// 确定
//
//                            break;
//                    }
//                    super.deal(which, obj);
//                }
//            });

//            skipOtherActivity(LanYaActivity.class,false);
//            skipOtherActivity(SelectActivity.class,false);
//        }


//        //发起微信登录
//        if (CompontApplayCation.iwxapi != null && CompontApplayCation.iwxapi.isWXAppInstalled()) {
//            SendAuth.Req req = new SendAuth.Req();
//            req.scope = "snsapi_userinfo";
//            req.state = "wechat_sdk_demo_test_neng";
//            CompontApplayCation.iwxapi.sendReq(req);
//        } else {
//            Toast.makeText(this, "用户未安装微信", Toast.LENGTH_SHORT).show();
        }

//        skipOtherActivity(PayActivity.class, false);
    }


}
